import { CoolController, BaseController } from '@cool-midway/core';
import { UserAdEntity } from '../../entity/ad';
import { UserAdService } from '../../service/adInfo';
import { UserInfoEntity } from '../../../user/entity/info';

/**
 * 用户-广告信息
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: UserAdEntity,
  service: UserAdService,
  pageQueryOp: {
    fieldEq: ['a.status', 'b.nickName', 'b.id'],
    select: ['a.*', 'b.avatarUrl', 'b.nickName'],
    join: [
      {
        entity: UserInfoEntity,
        alias: 'b',
        condition: 'a.userId = b.id',
        type: 'leftJoin',
      }
    ],
    where: ctx => {
      const { startTime, endTime } =
        ctx.request.body;
      return [
        // 过滤创建时间
        ['a.createTime >= :startTime', { startTime }, startTime],
        ['a.createTime <= :endTime', { endTime }, endTime],
      ];
    },
  },
})
export class AdminUserAdInfoController extends BaseController {}
